import QtQuick 2.2
import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.2
import QtQuick.Window 2.1

Window {
    visible: true
    width: 360
    height: 360

    QtObject {
        id: attrs;
        property int counter;
        Component.onCompleted: {
            attrs.counter = 10;
        }
    }

    Text {
        id: t;
        anchors.centerIn: parent;
        font{
            pixelSize: 30;
            weight: Font.Light;
            family: "微软雅黑";
        }
        color: "skyblue";
    }

    Timer {
        id: countDown;
        interval: 1000;
        repeat: true;
        triggeredOnStart: true;
        onTriggered: {
            var tmp = attrs.counter;
            attrs.counter--;
            if(tmp < 0){
                countDown.stop();
                t.text = "我~~~去~";
            }else{
                t.text = tmp;
            }
        }
    }

    Button {
        id: startButton;
        anchors.top: t.bottom;
        anchors.topMargin: 70;
        anchors.horizontalCenter: t.horizontalCenter;
        width: 100;
        height: 50;
        style: ButtonStyle {
            background: Rectangle {
                anchors.fill: parent;
                color: "skyblue";
                Text {
                    anchors.centerIn: parent;
                    color: "white";
                    font {
                        weight: Font.Light;
                        family: "微软雅黑";
                        pixelSize: 24;
                    }
                    text: "Start";
                }
            }
        }

        onClicked: {
            attrs.counter = 10;
            countDown.start();
        }
    }
}
